<template>
  <div class="count-container">
    <div class="count-title">
      <i
        v-if="icon"
        :class="icon"
      />
      <span>{{ title }}</span>
    </div>
    <div style="display: flex; align-items: center;justify-content: space-between; margin-top:auto;margin-bottom:auto">
      <div style="display: flex; align-items:flex-end;">
        <span class="count">
          {{ count }}
          <span style="font-weight: 200;font-size:12px">{{ unit }}</span>
        </span>
      </div>
      <slot />
    </div>
  </div>
</template>

<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    icon: {
      type: String
    },
    content: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      contentRegEx: /([\d\.]+)([a-zA-Z]+)/
    }
  },
  computed: {
    count() {
      const result = this.content.match(this.contentRegEx)
      console.log(result)
      if (result) {
        return this.content.match(this.contentRegEx)[1]
      } else {
        return this.content
      }
    },
    unit() {
      const result = this.content.match(this.contentRegEx)
      if (result) {
        return this.content.match(this.contentRegEx)[2]
      } else {
        return ''
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.count-container{
  background-color: #f5f6fa;
  border-radius:3px;
  padding: 5px;
  height: 100%;
  display: flex;
  flex-direction: column;

  .count{
    font-size: 19px;
    font-weight: 600;
  }

  .count-title{
    display: flex;
    align-items: center;

    *:nth-child(2){
      margin-left: 0.3rem;
    }
  }
}
</style>
